package com.twfpro.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则工具
 * 
 * @author 高文
 *
 */
public class RegexUtils
{
	/**
	 * 提取参数
	 * 
	 * @param targetStr
	 *            目标字符串
	 * @param patternStr
	 *            正则匹配式
	 * @return 提取的字符串
	 */
	public static String find(String targetStr, String patternStr)
	{
		Pattern pattern = Pattern.compile(patternStr);
		Matcher matcher = pattern.matcher(targetStr);
		if (matcher.find())
		{
			return matcher.group(1);
		}
		return null;
	}

	/**
	 * 是否匹配
	 * 
	 * @param targetStr
	 *            目标字符串
	 * @param patternStr
	 *            正则式
	 * @return true-匹配，false-不匹配
	 */
	public static Boolean matches(String targetStr, String patternStr)
	{
		Pattern pattern = Pattern.compile(patternStr);
		Matcher matcher = pattern.matcher(targetStr);
		return matcher.matches();
	}
}
